<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
//类型控制器
class FormController extends CommonController{
	private $model;
	public function __init(){
		//调用CommonController里面的构造函数
		parent::__init();
		//实例化form模型
	  	$this->model = new \Common\Model\Form;
	}
	
	public function index(){
		//分页
		$total = $this->model->count();
		$page = Page::row(12)->make($total);
		View::with('page',$page);
		//获得数据
		$data = $this->model->limit(page::limit())->get();
		View::with('data',$data);
		View::make();
	}
	//添加
	public function add(){
		if(IS_POST){
			if(!$this->model->store()) View::error($this->model->getError());
			View::success('添加成功',U('index'));
		}
		View::make();
	}
	//编辑
	public function edit(){
		//2.修改
		if(IS_POST){
			if($this->model->edit()) View::success('修改成功',U('index'));
			View::error($this->model->getError());
		}
		//1.获取旧数据
		$oldData = $this->model->where("fid=" . Q('get.fid',0,'intval'))->find();
		View::with('oldData',$oldData);
		View::make();
	}
	//删除
	public function del(){
		$this->model->where("fid=" . Q('get.fid',0,'intval'))->delete();
		View::success('删除成功',U('index'));
	}
}

 ?>